import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);

const routers = [{
	path: '/',
	name: 'home',
	props: true,
	component: resolve => require(['./components/home'], resolve),
	meta: {
		title: '首页'
	}
},{
	path: '/search/:key',
	name: 'search',
	props: true,
	component: resolve => require(['./components/search'], resolve),
	meta: {
		title: '搜索'
	}
},{
	path: '/goods',
	name: 'goods',
	props: true,
	component: resolve => require(['./components/goods'], resolve),
	meta: {
		title: '动态'
	}
},{
	path: '/user',
	name: 'user',
	props: true,
	component: resolve => require(['./components/user'], resolve),
	meta: {
		title: '我的个人中心'
	}
},{
	path: '/signin',
	name: 'signin',
	props: true,
	component: resolve => require(['./components/signin'], resolve),
	meta: {
		title: '登录'
	}
},{
	path: '/view/:channel/:day/:id',
	name: 'view',
	props: true,
	component: resolve => require(['./components/view'], resolve),
	meta: {
		title: '详情'
	}
},{
	path: '/map',
	name: 'map',
	props: true,
	component: resolve => require(['./components/map'], resolve),
	meta: {
		title: '城市公交查询'
	}
},{
	path: '/videos',
	name: 'videos',
	props: true,
	component: resolve => require(['./components/videos'], resolve),
	meta: {
		title: '视频'
	}
},{
	path: '/videoview/:id',
	name: 'videoview',
	props: true,
	component: resolve => require(['./components/videoview'], resolve),
	meta: {
		title: '视频播放'
	}
},{
	path: '/channel/:type',
	name: 'channel',
	props: true,
	component: resolve => require(['./components/channel'], resolve),
	meta: {
		title: '同源新闻'
	}
},{
	path: '/nodata',
	name: 'nodata',
	props: true,
	component: resolve => require(['./components/nodata'], resolve),
	meta: {
		title: '404'
	}
}];

const router = new VueRouter({
	base:'/',
	routes: routers
});

router.beforeEach((to, from, next) => {
	if (to.meta.title) {
		document.title = to.meta.title
	}
	next();
});

export default router;